home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
assocc1
/
example.frm
< prev
next >
Wrap
Text File
|
1995-09-06
|
4KB
|
170 lines
VERSION 2.00
Begin Form frmMain
BorderStyle = 1 'Fixed Single
Caption = "Assoc Example"
ClientHeight = 2685
ClientLeft = 4035
ClientTop = 3000
ClientWidth = 2010
Height = 3090
Left = 3975
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2685
ScaleWidth = 2010
Top = 2655
Width = 2130
Begin CommandButton btnExit
Caption = "Exit"
Height = 252
Left = 1320
TabIndex = 2
Top = 2280
Width = 612
End
Begin CommandButton btnAssoc
Caption = "Assoc"
Height = 372
Left = 120
TabIndex = 1
Top = 2160
Width = 852
End
Begin CommandButton btnArray
Caption = "Array"
Height = 372
Left = 120
TabIndex = 0
Top = 1680
Width = 852
End
Begin PictureBox Addrs
Height = 336
Left = 1560
ScaleHeight = 300
ScaleWidth = 300
TabIndex = 5
Top = 1680
Width = 336
End
Begin Label lblExplain2
AutoSize = -1 'True
Caption = "The output appears in the Debug window."
Height = 384
Left = 120
TabIndex = 4
Top = 960
Width = 1812
WordWrap = -1 'True
End
Begin Label lblExplain1
AutoSize = -1 'True
Caption = "Click on Array or Assoc to load names and addresses."
Height = 576
Left = 120
TabIndex = 3
Top = 120
Width = 1812
WordWrap = -1 'True
End
End
Option Explicit
Dim Surnames(1 To 100) As String, Addresses(1 To 100) As String
Sub Addrs_Enumerate (Key As String, Value As String)
Debug.Print Key, Value
End Sub
Sub btnArray_Click ()
Call TryArray
End Sub
Sub btnAssoc_Click ()
Call TryAssoc
End Sub
Sub btnExit_Click ()
Unload frmMain
End Sub
Sub TryArray ()
Dim DataFile As String
Dim Surname As String, Address As String
Dim I As Integer, N As Integer
' Set the full path for the data file
If Right$(App.Path, 1) = "\" Then
DataFile = App.Path & "ADDR.DAT"
Else
DataFile = App.Path & "\" & "ADDR.DAT"
End If
' Read in the names and addresses
Open DataFile For Input As #1
For I = 1 To 100
If EOF(1) Then N = I - 1: Exit For
Input #1, Surname
If EOF(1) Then N = I - 1: Exit For
' .. in case there was a blank line
Input #1, Address
Surnames(I) = Surname
Addresses(I) = Address
Next I
Close #1
' Dump the arrays to the Debug window
Debug.Print
Debug.Print "Array ..."
For I = 1 To N
Debug.Print Surnames(I), Addresses(I)
Next I
End Sub
Sub TryAssoc ()
Dim DataFile As String
Dim Surname As String, Address As String
Const ASSOC_ENUMERATE = 0
' Set the full path for the data file
If Right$(App.Path, 1) = "\" Then
DataFile = App.Path & "ADDR.DAT"
Else
DataFile = App.Path & "\" & "ADDR.DAT"
End If
' Read in the names and addresses
Open DataFile For Input As #1
Do Until EOF(1)
Input #1, Surname
If EOF(1) Then Exit Do
' .. in case there was a blank line
Input #1, Address
Addrs.Key = Surname
Addrs.Value = Address
Loop
Close #1
' Dump the arrays to the Debug window
Debug.Print
Debug.Print "Assoc ..."
Addrs.Key = ""
Do
Addrs.Key = Addrs.NextKey
If Addrs.Key = "" Then Exit Do
Debug.Print Addrs.Key, Addrs.Value
Loop
' Now dump them again using the Enumerate event
Debug.Print
Debug.Print "Assoc using Enumerate ..."
Addrs.Action = ASSOC_ENUMERATE
End Sub